Mechanically simplify the argument to localtime and gmtime in several
authorrobertlipe <robertlipe@gmail.com>
Sun, 27 Jan 2013 22:07:52 +0000 (22:07 +0000)
committerrobertlipe <robertlipe@gmail.com>
Sun, 27 Jan 2013 22:07:52 +0000 (22:07 +0000)
formats to make operator overload  easier to create for those.

gpsbabel/cet_util.cc
gpsbabel/csv_util.cc
gpsbabel/gpssim.cc
gpsbabel/magnav.cc
gpsbabel/nmea.cc
gpsbabel/pocketfms_bc.cc
gpsbabel/stmsdf.cc
gpsbabel/unicsv.cc
gpsbabel/xmlgeneric.cc

index b7721cef3e0eb86ac4a37c53103aa24e10e8cc67..3bdb49a45345002913c14411e27ab404490d91c2 100644 (file)
@@ -1045,8 +1045,10 @@ cet_convert_waypt(const waypoint* wpt)
     url_next->url = cet_convert_string(url_next->url);
     url_next->url_link_text = cet_convert_string(url_next->url_link_text);
   }
-  gc_data->placer = cet_convert_string(gc_data->placer);
-  gc_data->hint = cet_convert_string(gc_data->hint);
+  if (gc_data) {
+    gc_data->placer = cet_convert_string(gc_data->placer);
+    gc_data->hint = cet_convert_string(gc_data->hint);
+  }
 
   fs = wpt->fs;
   while (fs != NULL) {
index ff439b9e503562ed5470bcda48534218a53c1007..9f856ebb9d4a32c7ab32d4f3da686dc40942d49b 100644 (file)
@@ -1224,8 +1224,10 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp,
   case XT_ISO_TIME_MS:
     wpt->creation_time = xml_parse_time(s, &wpt->microseconds);
     break;
-  case XT_NET_TIME:
-    dotnet_time_to_time_t(atof(s), &wpt->creation_time, &wpt->microseconds);
+  case XT_NET_TIME: {
+    time_t tt = wpt->creation_time;
+    dotnet_time_to_time_t(atof(s), &tt, &wpt->microseconds);
+    }
     break;
   case XT_GEOCACHE_LAST_FOUND:
     waypt_alloc_gc_data(wpt)->last_found = yyyymmdd_to_time(s);
@@ -1939,8 +1941,9 @@ xcsv_waypt_pr(const waypoint* wpt)
       writebuff(buff, fmp->printfc, TIMET_TO_EXCEL(wpt->creation_time));
       break;
     case XT_TIMET_TIME:
-      /* time as a time_t variable */
-      writebuff(buff, fmp->printfc, wpt->creation_time);
+      /* time as a time_t variable */ {
+      time_t tt = wpt->creation_time;
+      writebuff(buff, fmp->printfc, tt); }
       break;
     case XT_TIMET_TIME_MS: {
       /* time as a time_t variable in milliseconds */
index 618463e7e2e60ec1904026ab5bca506cf717ee92..83482989dddfc62b16237508766223de6df2d71f 100644 (file)
@@ -124,9 +124,11 @@ gpssim_write_pt(const waypoint* wpt)
     int hms, ymd;
     struct tm* tm;
 
-    tm = gmtime(&wpt->creation_time);
+    const time_t tt = wpt->creation_time;
+    tm = gmtime(&tt);
     hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec;
     ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year;
+
     snprintf(tbuf, sizeof(tbuf), ",%d,%d",ymd, hms);
     strcat(obuf, tbuf);
   }
index 49a6a1e2862705bc297783359de9da8adbdd99cc..4ec0a6f1cd27c7e8be39aa4940380a3c197d0d03 100644 (file)
@@ -132,18 +132,19 @@ static void
 my_writewpt(const waypoint* wpt)
 {
   struct record* rec;
-  struct tm* tm;
   char* vdata;
-  time_t tm_t;
   const char* sn = global_opts.synthesize_shortnames ?
                    mkshort_from_wpt(mkshort_handle, wpt) :
                    wpt->shortname;
 
   rec = (struct record*) xcalloc(sizeof(*rec)+56,1);
 
+  time_t tm_t;
+  struct tm* tm;
   tm = NULL;
   if (wpt->creation_time) {
-    tm = gmtime(&wpt->creation_time);
+    const time_t tt = wpt->creation_time;
+    tm = gmtime(&tt);
   }
   if (!tm) {
     tm_t = current_time();
@@ -202,7 +203,7 @@ my_writewpt(const waypoint* wpt)
 static void
 data_write(void)
 {
-  static char* appinfo =
+  static const char* appinfo =
     "\0\x01"
     "User\0\0\0\0\0\0\0\0\0\0\0\0"
     "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
index f27da415961e3b97177341c67c4000139030058a..47ba567c38c891583f41157af3af0ccd69cbe33c 100644 (file)
@@ -1272,7 +1272,8 @@ nmea_trackpt_pr(const waypoint* wpt)
   lat = degrees2ddmm(wpt->latitude);
   lon = degrees2ddmm(wpt->longitude);
 
-  tm = gmtime(&wpt->creation_time);
+  time_t ct = wpt->creation_time;
+  tm = gmtime(&ct);
   if (tm) {
     hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec;
     ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year;
index e7f788492e2ffb7ded5148034df104a135168046..4b9e7cc5d2342388d22f3c84d25dff80c72c362b 100644 (file)
@@ -132,9 +132,11 @@ pocketfms_waypt_disp(const waypoint *wpt)
   struct tm *tm;
 
   memset(&bc, 0, sizeof(bc));
-  tm = localtime(&wpt->creation_time);
+  const time_t tt = wpt->creation_time;
+  tm = localtime(&tt);
   if (wpt->creation_time) {
-    tm = gmtime(&wpt->creation_time);
+    const time_t tt = wpt->creation_time;
+    tm = gmtime(&tt);
   }
 
   strcpy(bc.id, header_id);
index 3e69a41ab4d1deba68da9f47a1000218c85a8511..b2e548d5eaec1640046990eb816c60c5f01e5532 100644 (file)
@@ -585,7 +585,8 @@ track_disp_wpt_cb(const waypoint *wpt)
   track_points++;
   all_track_points++;
 
-  tm = *localtime(&wpt->creation_time);
+  time_t ct = wpt->creation_time;
+  tm = *localtime(&ct);
   strftime(tbuf, sizeof(tbuf), "%d.%m.%Y,%H:%M.%S", &tm);
 
   calculate(wpt, &dist, &speed, &course, NULL, NULL);
index 0b89aaf6aa9491eb6206d58f56c194ee13d9b3af..42d8d831fd6cdb97c0d778ad2317bdf8cd3f7b9f 100644 (file)
@@ -1641,7 +1641,7 @@ unicsv_waypt_disp_cb(const waypoint *wpt)
     }
   }
   if FIELD_USED(fld_fix) {
-    char *fix;
+    const char *fix;
     switch (wpt->fix) {
     case fix_none:
       fix = "none";
@@ -1726,7 +1726,8 @@ unicsv_waypt_disp_cb(const waypoint *wpt)
         time += atoi(opt_utc) * SECONDS_PER_HOUR;
         tm = *gmtime(&time);
       } else {
-        tm = *localtime(&wpt->creation_time);
+        const time_t tt = wpt->creation_time;
+        tm = *localtime(&tt);
       }
       tm.tm_year += 1900;
       tm.tm_mon += 1;
@@ -1746,7 +1747,8 @@ unicsv_waypt_disp_cb(const waypoint *wpt)
         time += atoi(opt_utc) * SECONDS_PER_HOUR;
         tm = *gmtime(&time);
       } else {
-        tm = *localtime(&wpt->creation_time);
+        const time_t tt = wpt->creation_time;
+        tm = *localtime(&tt);
       }
       snprintf(buf, sizeof(buf), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec);
 
index 53c85fdfa753003dc793d199aa2be489f2791f9c..70703097fee3d17eae1741eb87c8a37d0fec6b76 100644 (file)
@@ -105,7 +105,7 @@ void
 xml_fill_in_time(char *time_string, const time_t timep, int microseconds, int long_or_short)
 {
   struct tm *tm = gmtime(&timep);
-  char *format;
+  const char *format;
   int n;
 
   if (!tm) {
@@ -145,7 +145,6 @@ xml_write_time(gbfile *ofd, const time_t timep, int microseconds, const char *el
               elname
              );
   }
-
 }
 
 /***********************************************************************
@@ -301,7 +300,7 @@ void xml_readstring(char *str)
   XML_ParserFree(psr);
 }
 
-void xml_readprefixstring(char *str)
+void xml_readprefixstring(const char *str)
 {
   int len = strlen(str);
   if (!XML_Parse(psr, str, len, 0)) {